using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using SMWJamecl.BusinessEntities;

namespace SMWJamecl.Repository.Mapping
{
    public class ComponenteMap : EntityTypeConfiguration<Componente>
    {
        public ComponenteMap()
        {
            // Primary Key
            this.HasKey(t => t.Id_Componente);

            // Properties
            this.Property(t => t.Id_Componente)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.Descripcion)
                .IsRequired()
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("Componente");
            this.Property(t => t.Id_Componente).HasColumnName("Id_Componente");
            this.Property(t => t.Descripcion).HasColumnName("Descripcion");

            // Relationships
            this.HasMany(t => t.Vehiculoes)
                .WithMany(t => t.Componentes)
                .Map(m =>
                    {
                        m.ToTable("CheckList");
                        m.MapLeftKey("ComponenteId");
                        m.MapRightKey("PlacaVehiculo");
                    });


        }
    }
}
